package com.meritdata.cloud.data.standard.directory.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.meritdata.cloud.data.base.ResultData;
import com.meritdata.cloud.data.standard.directory.service.IDataLayerService;
import com.meritdata.cloud.utils.SessionUtils;

@RestController
@RequestMapping("/directory/layer")
public class DataLayerController {

	@Autowired
	private IDataLayerService layerService;

	@Autowired
	private SessionUtils sessionUtils;

	@RequestMapping("/tree")
	public ResultData tree(HttpServletRequest request) {
		ResultData result = new ResultData();
		result.setData(layerService.tree());
		return result;
	}
	
	@RequestMapping("/list")
	public ResultData list(HttpServletRequest request) {
		ResultData result = new ResultData();
		result.setData(layerService.list());
		return result;
	}
	
	@RequestMapping("/get")
	public ResultData get(HttpServletRequest request, @RequestParam long id) {
		ResultData result = new ResultData();
		result.setData(layerService.get(id));
		return result;
	}

	@RequestMapping("/create")
	public ResultData create(HttpServletRequest request, @RequestParam String name, @RequestParam String code,
			@RequestParam String description) {
		return layerService.create(name, code, description, sessionUtils.getCurrentUserId());
	}

	@RequestMapping("/delete")
	public ResultData delete(HttpServletRequest request, @RequestParam long id) {
		return layerService.delete(id);
	}

	@RequestMapping("/update")
	public ResultData update(HttpServletRequest request, @RequestParam String name, @RequestParam String code,
			@RequestParam String description, @RequestParam long id) {
		return layerService.update(name, code, description, id, sessionUtils.getCurrentUserId());
	}

}
